home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1991-1995 by TopSoft Inc. All rights reserved.
-
- You may distribute this file under the terms of the TopSoft
- Artistic License, accompanying this package.
-
- This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
- See the Modification History for more details.
-
- Product
- About Box
-
- FILE
- ABSound.c
-
- NAME
- ABSound.c, part of the ABox project source code,
- responsible for handling the AboutBox Sound class stuff.
-
- DESCRIPTION
- This file contains defines for the about box modules.
-
- DEVELOPED BY
- George (ty) Tempel netromancr@aol.com
- All code in this file, and its associated header file was
- Created by George (ty) Tempel in connection with the TopSoft, Inc.
- "FilterTop" application development, except where noted.
-
- CARETAKER - George (ty) Tempel <netromancr@aol.com>
- Please consult this person for any changes or suggestions to this file.
-
- MODIFICATION HISTORY
-
- dd mmm yy - xxx - patchxx: description of patch
- 10 June 94 - ty - Initial Version Created
- 20-july-94 - ty - initial version released
- 28-july-94 - ty - 1.0.6 -- additions to play sound only if
- the caller has set the ABox property
- kABoxUseSoundMgr
- 12-jan-95 - ty - 1.1 -- edits to compensate for the differences
- between apple's universal headers releases...
- i'll assume the newest stuff as the default
- 23-may-95 - ty - changes for compatibility with the CodeWarrior CW6
- release and the associated Universal Headers from Apple:
- most methods that returned references now have "Ref" at
- the end of their methods names to prevent possible collisions
- with datatypes and classes of the same name (older versions
- of the compiler didn't have a problem with this).
- */
-
- /*===========================================================================*/
-
- /*======= Segmentation directives ========*/
-
- #ifdef USE_MANUAL_SEGMENTATION
- #pragma segment ty
- #endif
-
- /*============ Header files ==============*/
-
- #include "ABSound.h"
- #include "ABox.h"
-
- /*=============== Globals ================*/
-
- /*================ CODE ==================*/
-
-
- /*=============================== ABSound::ABSound ================================*/
- ABSound::ABSound(void)
- {
- mSoundChannelDone = false; // used to indicate the channel should close down
- mSoundChannelPtr = NULL; // the sound channel per-se
- mSoundCallbackUPP = NULL;
- //soundSignature = ++counter; // create a unique signature
- mResType = kABSoundResource;
- } // end ABSound
-
-
-
- /*=============================== ABSound::~ABSound ================================*/
- ABSound::~ABSound(void)
- {
- Stop();
-
- } // end ~ABSound
-
-
-
-
-
- /*=============================== ABSound::Draw ================================*/
- OSErr ABSound::Draw(WindowPtr window)
- {
-
- OSErr error = noErr;
-
- // begin here...
- //
-
- error = ABObject::Draw(window);
-
- if (this->HasWindow())
- {
- // 1.0.6 ty--check to see if we're allowed to use the DragMgr
- //
- ABox *theABox = (ABox *)::GetWRefCon (this->OurWindowRef());
- Boolean useSnd = true;
-
- if (theABox)
- error = theABox->GetProperty(kABoxUseSoundMgr, &useSnd, NULL);
-
- if (!useSnd)
- return error;
- } // end if block
-
- this->SoundCallback() = NewSndCallBackProc (DoSnd_done);
- error = ::SndNewChannel (&this->SoundChannelPointer(), 0, 0, this->SoundCallback());
-
- error = this->InitializeResource();
-
- // 1.1 edits to compensate for the differences between apple's universal
- // headers releases...i'll assume the newest stuff as the default
- #ifdef soundListRsrc
- // older version 1 universal headers
- #define SndListHandle ResourceHandle
- #else
- // assume newer verions 2 universal headers
- #endif
- // 1.1--edits for new universal headers
- SndListHandle theSndListHandle = (SndListHandle)this->ResourceHandleRef();
-
- if (error)
- {
- // couldn't get a sound channel, so do it synchronously. Sigh.
- this->SoundChannelPointer() = NULL;
- this->SoundChannelDone() = false;
-
- error = ::SndPlay (NULL, theSndListHandle, false /* false = synchronous */);
- if (error)
- {
- //ABoxDebug(kABErrSndPlaySync, error);
- } // end if block
- } else {
-
- // send the sound down the channel, followed by a callback command
- // to close the channel...see note below
-
- error = ::SndPlay (this->SoundChannelPointer(), theSndListHandle, true /* true = asynchronous*/);
- if (error)
- {
- // problems playing async, so trash the channel and do it sync
- //
- this->SoundChannelDone() = true;
- this->Stop();
- error = ::SndPlay (NULL, theSndListHandle, false /* false = synchronous */);
- if (error)
- {
- //ABoxDebug(kABErrSndPlaySync, error);
- } // end if block
- } else {
- // no problems, play it async...
- //
-
- this->SoundChannelDone() = false;
-
- } // end if else block...
-
- } // end if (error) block on SndNewChannel status
-
- // now return to the caller...
-
- return error;
- } // end Draw
-
-
-
-
-
- /*=============================== ABSound::Update ================================*/
- OSErr ABSound::Update(WindowPtr window)
- {
-
- // begin here...
- //
-
- this->OurWindowRef() = window;
- return noErr;
- } // end Update
-
-
-
-
-
- /*=============================== DoSnd_done ===============================*/
- //
- // a function to close down a sound channel.
- //
- // this function is called via an interrupt by the sound manager if
- // we queued a sound into a channel.
- //
- // is called by:
- // the asynchronous portion of the sound manager
- //
- pascal void ABSound::DoSnd_done (SndChannelPtr /*channel*/, SndCommand *command)
- {
- OSErr error = noErr;
-
- long otherA5;
-
- // Look for our "callback signature" in the sound command.
- // from: SoundHelper.c - the Asynchronous Sound Helper,
- // Apple DTS, by Bryan K. Ressler (Beaker), 2/4/92
- //
- // This routine first looks for our "completion signature." This is how we know
- // that the callback really means the sound has completed. There is a bug in the
- // Sound Manager that may cause callbacks that weren't specifically requested, and
- // this constant allows us to distinguish our "real" callback from one that is a
- // result of that bug. If the callback is hip the channel can be freed.
- //
-
- if (!command) // 1.0a5 ty...added check just to be sure
- return;
-
- if (command->param1 == kABSoundSignature)
- {
- // close down the sound channel...
- //
- otherA5 = ::SetA5(command->param2); // Set up our A5
- //
- // NEVER EVER EVER play with memory here...you can't guarantee where it
- // really is because we've been called at interrupt time! Instead
- // set a global flag that someone else can see and act upon! I learned
- // this the _hard_ way...
- //
- //gSoundChannelDone = true;
- ::SetA5(otherA5); // Retore old A5
-
- } // end if block...
-
- return;
- } // end of function DoSnd_done()
-
-
-
-
-
- /*=============================== ABSound::Stop ================================*/
- OSErr ABSound::Stop(void)
- {
- OSErr error = noErr;
- Boolean quietNow = true;
- SndCommand command; // 1.0a3 patch ty ... moved to this block from below
-
- if (this->DoesntHaveSoundChannelPointer())
- {
- // false alarm...
- return error;
-
- } else {
- command.cmd = quietCmd; // 1.0a4p2 ty...added a quietCmd here
- command.param1 = kABnoSoundParam1;
- command.param2 = kABnoSoundParam2;
- error = ::SndDoImmediate (this->SoundChannelPointer(), &command);
-
- command.cmd = flushCmd;
- command.param1 = kABnoSoundParam1;
- command.param2 = kABnoSoundParam2;
- error = ::SndDoImmediate (this->SoundChannelPointer(), &command);
-
- command.cmd = quietCmd;
- command.param1 = kABnoSoundParam1;
- command.param2 = kABnoSoundParam2;
- error = ::SndDoImmediate (this->SoundChannelPointer(), &command);
-
- // a slight delay has been added here before we go on
- // to kill the sound channel. This seems to stop the
- // chirp or squeak that sometimes occurs
- command.cmd = waitCmd;
- command.param1 = kABsoundDelayHalfMilliseconds;
- command.param2 = kABnoSoundParam2;
- error = ::SndDoImmediate (this->SoundChannelPointer(), &command);
-
- this->SoundChannelDone() = true;
- } // end if block
-
- if (this->IsSoundChannelDone() && this->HasSoundChannelPointer())
- {
- //ABoxDebugDelete ();
- error = ::SndDisposeChannel (this->SoundChannelPointer(), quietNow);
- this->SoundChannelPointer() = NULL;
- this->SoundChannelDone() = false;
- } // end if block to wipe out the sound channel.
-
- if (this->HasSoundCallback())
- {
- //ABoxDebugDelete();
- DisposeRoutineDescriptor (this->SoundCallback());
- } // end if block
-
-
- error = ABResource::Stop();
-
- return error;
-
- } // end Stop
-
-
-
-
-
- // end of file
-
-